#pragma once
/*
 * TCP net handler for client.
 */
#include <functional>
#include <map>
#include <vector>
#include "singleton.h"
#include "rpc/rpc_handle.hpp"
#include "proto.h"
#include "redis_client.h"

// declare client handler.
class CClientHandler;
class CCliSession;
using handleFunc = std::function<void(CCliSession* pCliSession, const char* proto, int len)>;

// TCP net handler.
class CClientHandler final {
	DECLARE_SINGLETON(CClientHandler);
protected:
	CClientHandler() = default;
	virtual ~CClientHandler() = default;

public:
	// Init initialize the TCP handler.
	void Init();

	// HandleMsg handle message.
	bool HandleMsg(CCliSession* pCliSession, const char* msg, int len);

protected:
	// handlePing handle ping.
	void handlePing(CCliSession* pCliSession, const char* proto, int len);

private:
	// protocol handlers.
	std::map<unsigned short, handleFunc> m_handlers;
};